﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    <title></title>
    <script type="text/javascript" src="js/jquery-1.10.2.js"></script>
    <script type="text/javascript" src="js/awardrotate.js"></script>
    <link rel="stylesheet" type="text/css" href="css/index.css">
</head>
<body>
<div class="w1400-img"><img src="images/ld1.jpg" alt=""/></div>
<div class="lucyDraw">
    <div class="turnplate">
        <canvas class="item" id="wheelcanvas" width="422px" height="422px"></canvas>
        <img class="pointer" src="images/turnplate-pointer.png"/>
    </div>
</div>
<div class="deepTime">
    您还有<span>1次</span>抽奖机会
</div>
<div class="w1400-img zjdt"><img src="images/ld3.jpg" alt=""/>
    <div class="w754"><a class="my">我的中奖</a></div>
</div>
<div class="w754_2">
    <table class="th" width="100%" cellpadding='0' cellspacing='0'>
        <tr>
            <th width="30%">时间</th>
            <th width="30%">用户</th>
            <th width="40%">奖项</th>
        </tr>
    </table>
    <div class="marqueeBox">
        <table width="100%" cellpadding='0' cellspacing='0' id="marquee">
            <tr>
                <td width="30%" colspan="3">暂无中奖数据</td>
            </tr>
        </table>
    </div>
</div>
<div class="w1400-img setting">
    <img src="images/ld4.jpg" alt="">
    <div class="w754"><img src="images/ld5.jpg" alt=""></div>
</div>
<div class="w1400-img rule">
    <img src="images/ld6.jpg" alt="">
</div>
<div class="w754_2">
    <div class="txt">
        1、 凡订单金额每满2000元，即可获赠一次抽奖机会，100%中奖。
        <br>2、 只有真实有效订单号才可获奖，退订单、虚假订单将取消其获奖资格。
        <br> 3、 实物奖品将在活动结束一个月后统一配送，请抽奖者认真填写配送信息。
        <br>4、 活动截止时间：2021年12月31日 24:00
    </div>
</div>
<div class="shadowBox">
    <div class="bigBox">
        <div class="prize itemBox">
            <div class="close"></div>
            <div class="pic"><img src="images/pz1.png" alt=""></div>
            <div class="title">小米电视</div>
            <div class="btn">填写收件信息</div>
        </div>
    </div>
    <div class="bigBox">
        <div class="writeInfo itemBox">
            <div class="close"></div>
            <form action="">
                <h3>恭喜您抽到<span>小米电视</span></h3>
                <ul>
                    <li><label>姓名：</label><input type="text" name=""></li>
                    <li><label>电话：</label><input type="text" name=""></li>
                    <li><label>地址：</label><input type="text" name=""></li>
                    <li><label>备注：</label><input type="text" name=""></li>
                    <li>
                        <div class="sub">提交信息</div>
                    </li>
                </ul>
            </form>
        </div>
    </div>
    <div class="bigBox">
        <div class="subSuccess itemBox">
            <div class="close"></div>
            <div class="my">我的中奖</div>
        </div>
    </div>
    <div class="bigBox">
        <div class="noList itemBox">
            <div class="close"></div>
            <div class="close2">立刻抽奖</div>
        </div>
    </div>

    <div class="bigBox">
        <div class="hadList itemBox">
            <div class="close"></div>
            <table class="thead">
                <tr>
                    <th>奖项</th>
                    <th>抽奖时间</th>
                </tr>
            </table>
            <div class="listBox">
                <table>
                    <tr>
                        <td class="red">小米电视</td>
                        <td>2022-2-12 10:01:28</td>
                    </tr>
                    <tr>
                        <td class="red">小米电视</td>
                        <td>2022-2-12 10:01:28</td>
                    </tr>
                    <tr>
                        <td class="red">小米电视</td>
                        <td>2022-2-12 10:01:28</td>
                    </tr>
                    <tr>
                        <td class="red">小米电视</td>
                        <td>2022-2-12 10:01:28</td>
                    </tr>
                    <tr>
                        <td class="red">小米电视</td>
                        <td>2022-2-12 10:01:28</td>
                    </tr>
                    <tr>
                        <td class="red">小米电视</td>
                        <td>2022-2-12 10:01:28</td>
                    </tr>
                    <tr>
                        <td class="red">小米电视</td>
                        <td>2022-2-12 10:01:28</td>
                    </tr>
                </table>
            </div>
            <div class="back">返回首页</div>
        </div>
    </div>
    <div class="bigBox">
        <div class="noDeefTime itemBox">
            <div class="close"></div>
            <div class="close2">返回首页</div>
        </div>
    </div>
</div>
</body>
<script>
    $(function () {
        loadRecordData();
        var marquee = document.getElementById('marquee');
        var offset = 0;
        var scrollheight = marquee.offsetHeight;
        var firstNode = marquee.children[0].cloneNode(true);
        marquee.appendChild(firstNode);//还有这里
        function mq() {
            if (offset == scrollheight) {
                offset = 0;
            }
            marquee.style.marginTop = "-" + offset + "px";
            offset += 1;
        }

        var t;
        t = setInterval(mq, 50);
        $("#marquee").hover(function () {
            window.clearInterval(t);
        }, function () {
            t = setInterval(mq, 50);
        });
        if (($('#marquee tr').length) / 2 <= 4) {
            window.clearInterval(t);
        }
        $('#marquee tr').each(function (index, domEle) {
            // domEle == this
            var name = $(domEle).find('td:eq(1)').text();
            var nameAfter = name.substr(0, 3) + "****" + name.substr(7);
            $(domEle).find('td:eq(1)').text(nameAfter);

        });
    });

    function loadRecordData() {
        $.ajax({
            type: "get",
            url: "/lottery-record",
            cache: false,
            async: false,
            success: function (data) {
                var html = "";
                data.result.forEach(function (item, index) {
                    var trStr = "<tr><td width='30%'>" + item.prizeName + "</td></td><td width='30%'>" + item.accountIp + "</td><td width='40%'>" + item.createTime + "</td></tr>";
                    html += trStr;
                });
                if (html != "") {
                    $("#marquee").html(html);
                }
            }
        });
    }
</script>
<script type="text/javascript">
    var turnplate = {
        restaraunts: [],				//大转盘奖品名称
        colors: [],					//大转盘奖品区块对应背景颜色
        outsideRadius: 212,			//大转盘外圆的半径
        textRadius: 155,				//大转盘奖品位置距离圆心的距离
        insideRadius: 45,			//大转盘内圆的半径
        startAngle: 0,				//开始角度
        bRotate: false				//false:停止;ture:旋转
    };

    $(document).ready(function () {
        //动态添加大转盘的奖品与奖品区域背景颜色
        turnplate.restaraunts = ["小米电视", "苹果耳机", "摄影背包", "三脚架套餐", "移动电源", "记事本"];
        turnplate.colors = ["transparent", "transparent", "transparent", "transparent", "transparent", "transparent"];

        //旋转转盘 item:奖品位置; txt：提示语;
        var rotateFn = function (item, txt) {
            var angles = item * (360 / turnplate.restaraunts.length) - (360 / (turnplate.restaraunts.length * 2));
            if (angles < 270) {
                angles = 270 - angles;
            } else {
                angles = 360 - angles + 270;
            }
            $('#wheelcanvas').stopRotate();
            $('#wheelcanvas').rotate({
                angle: 0,
                animateTo: angles + 1800,
                duration: 8000,
                callback: function () {
                    if (item == -1) {
                        $('.shadowBox .prize .pic img').attr('src', 'images/pz1.png');
                    }
                    if (item == -0) {
                        $('.shadowBox .prize .pic img').attr('src', 'images/pz2.png');
                    }
                    if (item == 1) {
                        $('.shadowBox .prize .pic img').attr('src', 'images/pz3.png');
                    }
                    if (item == 2) {
                        $('.shadowBox .prize .pic img').attr('src', 'images/pz4.png');
                    }
                    if (item == 3) {
                        $('.shadowBox .prize .pic img').attr('src', 'images/pz5.png');
                    }
                    if (item == 4) {
                        $('.shadowBox .prize .pic img').attr('src', 'images/pz6.png');
                    }

                    $('.shadowBox .prize .title').text(txt);
                    $('.shadowBox').fadeIn();
                    $('.shadowBox .prize').fadeIn();

                    turnplate.bRotate = !turnplate.bRotate;
                }
            });
        };
        $('.shadowBox .itemBox .close').click(function () {
            $('.shadowBox .itemBox').fadeOut();
            $('.shadowBox').fadeOut();
        })
        //立刻抽奖
        $('.shadowBox .itemBox .close2,.hadList .back').click(function () {
            window.location.reload();
        })
        $('.shadowBox .prize .btn').click(function () {
            $('.shadowBox .writeInfo').fadeIn();
        })
        $('.shadowBox .writeInfo .sub').click(function () {
            $('.shadowBox .subSuccess').fadeIn();
        })
        $('.subSuccess .my').click(function () {
            $('.shadowBox .hadList').fadeIn();
        })

        $('.pointer').click(function () {
            if (turnplate.bRotate) return;
            turnplate.bRotate = !turnplate.bRotate;
            //获取随机数(奖品个数范围内)
            $.ajax({
                type: "get",
                url: "/lottery/1",
                cache: false,
                async: false,
                success: function (data) {
                    if (data.code == "0000") {
                        console.log(data);
                        //奖品数量等于10,指针落在对应奖品区域的中心角度[252, 216, 180, 144, 108, 72, 36, 360, 324, 288]
                        rotateFn(data.result.level - 2, data.result.prizeName);
                    } else {
                        alert(data.msg);
                    }
                }
            });
        });
    });
    //页面所有元素加载完毕后执行drawRouletteWheel()方法对转盘进行渲染
    window.onload = function () {
        drawRouletteWheel();
    };

    function drawRouletteWheel() {
        var canvas = document.getElementById("wheelcanvas");
        if (canvas.getContext) {
            //根据奖品个数计算圆周角度
            var arc = Math.PI / (turnplate.restaraunts.length / 2);
            var ctx = canvas.getContext("2d");
            //在给定矩形内清空一个矩形
            ctx.clearRect(0, 0, 422, 422);
            //strokeStyle 属性设置或返回用于笔触的颜色、渐变或模式
            ctx.strokeStyle = "transparent";
            //font 属性设置或返回画布上文本内容的当前字体属性
            ctx.font = '16px Microsoft YaHei';
            for (var i = 0; i < turnplate.restaraunts.length; i++) {
                var angle = turnplate.startAngle + i * arc;
                ctx.fillStyle = turnplate.colors[i];
                ctx.beginPath();
                //arc(x,y,r,起始角,结束角,绘制方向) 方法创建弧/曲线（用于创建圆或部分圆）
                ctx.arc(211, 211, turnplate.outsideRadius, angle, angle + arc, false);
                ctx.arc(211, 211, turnplate.insideRadius, angle + arc, angle, true);
                ctx.stroke();
                ctx.fill();
                //锁画布(为了保存之前的画布状态)
                ctx.save();

                //----绘制奖品开始----
                ctx.fillStyle = "transparent";
                var text = turnplate.restaraunts[i];
                var line_height = 17;
                //translate方法重新映射画布上的 (0,0) 位置
                ctx.translate(211 + Math.cos(angle + arc / 2) * turnplate.textRadius, 211 + Math.sin(angle + arc / 2) * turnplate.textRadius);
                //rotate方法旋转当前的绘图
                ctx.rotate(angle + arc / 2 + Math.PI / 2);
            }
        }
    }

</script>
</html>